package compiler;

import compiler.antlr.inputAST;
import compiler.antlr.inputLexer;
import compiler.antlr.inputParser;
import compiler.grammar.Grammar;
import compiler.grammar.NonTerminal;
import compiler.grammar.Production;
import compiler.grammar.Terminal;
import compiler.parser.ParserGen;
import compiler.parser.lalr.LALRState;
import compiler.scanner.dfa.DFAState;
import compiler.scanner.nfa.NFAState;
import org.antlr.runtime.ANTLRFileStream;
import org.antlr.runtime.CommonTokenStream;
import org.antlr.runtime.Lexer;
import org.antlr.runtime.tree.CommonTree;
import org.antlr.runtime.tree.CommonTreeNodeStream;
import java.io.File;

public class Main
{
    //~ Methods ----------------------------------------------------------------

    public static void main(String[] args) throws Exception
    {
        for (int i : new int[]{5})
        {
            Terminal.reset();
            NonTerminal.reset();
            Production.reset();
            LALRState.reset();
            DFAState.reset();
            NFAState.reset();

            System.out.println("Test " + i);

            String                         fileName = "./testcases/test" + i;
            ANTLRFileStream                stream = new ANTLRFileStream(fileName);
            Lexer                          lexer = new inputLexer(stream);
            CommonTokenStream              tokenStream = new CommonTokenStream(lexer);
            inputParser                    _inputParser = new inputParser(tokenStream);
            inputParser.grammarSpec_return tree = _inputParser.grammarSpec();
            CommonTree                     commonTree = (CommonTree)tree.getTree();
            CommonTreeNodeStream           nodeStream = new CommonTreeNodeStream(commonTree);
            Grammar                        g = new inputAST(nodeStream).grammarSpec();

            new ParserGen(g).process("./testcases/", "test" + i);
            new ProcessBuilder("./translateGraphs.sh").directory(new File("./testcases")).start().waitFor();
        }
    }
}
